package com.yzh.wanandroid.vm

import android.app.Application
import androidx.lifecycle.LifecycleOwner
import com.yzh.wanandroid.base.BaseFragmentViewModel
import com.yzh.wanandroid.component.app.MainApplication
import com.yzh.wanandroid.model.CatchData
import com.yzh.wanandroid.utils.CacheDataUtil
import com.yzh.wanandroid.utils.VersionUtils

class SettingFragmentVm(application: Application) : BaseFragmentViewModel(application) {

    val TAG = "SettingFragmentVm"

    private val catchUtils: CacheDataUtil by lazy { CacheDataUtil() }

    private val versionUtils: VersionUtils by lazy { VersionUtils() }

    val catchData: CatchData by lazy { CatchData() }

    override fun onCreate(owner: LifecycleOwner) {
        super.onCreate(owner)
        getCatchSize()
    }

    /**
     *  清空缓存
     */
    fun clearCatch() {
        catchUtils.clearAllCache(MainApplication.appContext)
        getCatchSize()
    }

    /**
     *  获取缓存大小
     */
    private fun getCatchSize() {
        catchData.catchSize = catchUtils.getTotalCacheSize(MainApplication.appContext)
    }

    /**
     * 获取版本号
     */
    fun getVerSion(): String? {
        return versionUtils.packageName(MainApplication.appContext)
    }
}